package com.example.demo.leetcode.classics150;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _67LRU缓存
 * @description
 * @date 2023/07/30 14:44
 * <p>
 * ******************************************************
 */
public class _67LRU缓存 extends LinkedHashMap<Integer, Integer> {

    private int capacity;

    @Override
    public Integer get(Object key) {
        return super.get(key) == null ? -1 : super.get(key);
    }

    @Override
    public Integer put(Integer key, Integer value) {
        return super.put(key, value);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<Integer, Integer> eldest) {
        return size() > capacity;
    }


    public _67LRU缓存(int capacity) {
        super(capacity, 0.75f, true);
        this.capacity = capacity;
    }
}
